<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>insert</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C++ Strings</a> &gt; <a href="insert.html">insert</a>
  </div>

  <div class="name-format">
    insert
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;string&gt;
  iterator insert( iterator i, const char&amp; ch );
  string&amp; insert( <strong>size_type</strong> index, const string&amp; str );
  string&amp; insert( <strong>size_type</strong> index, const char* str );
  string&amp; insert( <strong>size_type</strong> index1, const string&amp; str, <strong>size_type</strong> index2, <strong>size_type</strong> num );
  string&amp; insert( <strong>size_type</strong> index, const char* str, <strong>size_type</strong> num );
  string&amp; insert( <strong>size_type</strong> index, <strong>size_type</strong> num, char ch );
  void insert( iterator i, <strong>size_type</strong> num, const char&amp; ch );
  void insert( iterator i, iterator start, iterator end );
</pre>

  <p>The very multi-purpose insert() function either:</p>

  <ul>
    <li>inserts <em>ch</em> before the character denoted by
    <em>i</em>,</li>

    <li>inserts <em>str</em> into the current string, at location
    <em>index</em>,</li>

    <li>inserts a substring of <em>str</em> (starting at
    <em>index2</em> and <em>num</em> characters long) into the current
    string, at location <em>index1</em>,</li>

    <li>inserts <em>num</em> characters of <em>str</em> into the
    current string, at location <em>index</em>,</li>

    <li>inserts <em>num</em> copies of <em>ch</em> into the current
    string, at location <em>index</em>,</li>

    <li>inserts <em>num</em> copies of <em>ch</em> into the current
    string, before the character denoted by <em>i</em>,</li>

    <li>or inserts the characters denoted by <em>start</em> and
    <em>end</em> into the current string, before the character
    specified by <em>i</em>.</li>
  </ul>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="erase.html">erase</a><br>
    <a href="replace.html">replace</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
